package org.stvd.service.quartz.impl;

import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.stvd.entities.quartz.QuartzJob;
import org.stvd.service.quartz.QuartzJobService;
 
/**
 * 调用job
 * @author Administrator
 * 
 */
public class JobInitService {
 
    @Autowired
    private QuartzHandler quartzHandler;
    
    @Autowired
    private QuartzJobService quartzJobService;
 
    /**
     * 初始化定时任务
     * @throws SchedulerException
     */
    public void loadJobInit() throws SchedulerException {
        quartzHandler.deleteAllJobs();
        for (QuartzJob quartzJob : quartzJobService.listEnabledQuartzJob()) {
            try {
                Class<?> clazz = Class.forName(quartzJob.getBeanClass());
                quartzHandler.start(quartzJob, clazz);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
 
}
